<template>
  <div>
    <el-breadcrumb>
      <el-breadcrumb-item>货代管理查询</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-table :data="repalist" stripe style="width: 100%">>
          <el-table-column
            prop="fc_id"
            label="业务号"
            width="100">
          </el-table-column>
          <el-table-column
            prop="fc_name"
            label="公司名称"
            width="100">
          </el-table-column>
          <el-table-column
            prop="fc_address"
            label="公司地址"
            width="100">
          </el-table-column>
          <el-table-column
            prop="fc_phone"
            label="公司电话"
            width="150">
          </el-table-column>
          <el-table-column
            label="操作">
            <template slot-scope="scope">
              <el-button type="primary" icon="el-icon-edit" @click="showUpdataDialog(scope.row)" circle></el-button>
              <el-button type="danger" icon="el-icon-delete" @click="showDeleteDialog(scope.row)" circle></el-button>
            </template>
          </el-table-column>
        </el-table>
    </el-card>
    <el-dialog
        :visible.sync="updataDialogVisible"
        width="30%">
        <el-form :model="formvalue" label-width="100px">
          <el-form-item label="业务号">
            <el-input v-model="formvalue.fc_id" :disabled="true" ></el-input>
          </el-form-item>
          <el-form-item label="公司名称">
            <el-input v-model="formvalue.fc_name"></el-input>
          </el-form-item>
          <el-form-item label="公司地址">
            <el-input v-model="formvalue.fc_address"></el-input>
          </el-form-item>
          <el-form-item label="公司电话">
            <el-input v-model="formvalue.fc_phone"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="updataDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="updatafc">确 定</el-button>
        </span>
     </el-dialog>
     <el-dialog
         :visible.sync="deleteDialogVisible"
         width="30%">
         <el-form :model="formvalue" label-width="100px">
           <el-form-item label="业务号">
             <el-input v-model="formvalue.fc_id" :disabled="true" ></el-input>
           </el-form-item>
           <el-form-item label="公司名称">
             <el-input v-model="formvalue.fc_name" :disabled="true"></el-input>
           </el-form-item>
           <el-form-item label="公司地址">
             <el-input v-model="formvalue.fc_address" :disabled="true"></el-input>
           </el-form-item>
           <el-form-item label="公司电话">
             <el-input v-model="formvalue.fc_phone" :disabled="true"></el-input>
           </el-form-item>
         </el-form>
         <span slot="footer" class="dialog-footer">
           <el-button @click="updataDialogVisible = false">取 消</el-button>
           <el-button type="primary" @click="deletefc">确 定</el-button>
         </span>
      </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      repalist: [],
      updataDialogVisible: false,
      deleteDialogVisible: false,
      formvalue: {}
    }
  },
  created() {
    this.getFclist()
  },
  methods: {
    async getFclist() {
      const { data: res } = await this.$http.get('forwardercompany')
      this.repalist = res.data.value
    },
    showUpdataDialog(rowvalue) {
      this.updataDialogVisible = true
      this.formvalue = rowvalue
    },
    async updatafc() {
      const { data: res } = await this.$http.put('forwardercompany', {
        fc_id: this.formvalue.fc_id,
        fc_name: this.formvalue.fc_name,
        fc_address: this.formvalue.fc_address,
        fc_phone: this.formvalue.fc_phone
      })
      console.log(res.code)
      this.getFclist()
      this.updataDialogVisible = false
    },
    showDeleteDialog(rowvalue) {
      this.deleteDialogVisible = true
      console.log(rowvalue)
      this.formvalue = rowvalue
    },
    async deletefc() {
      const { data: res } = await this.$http.delete('forwardercompany?fc_id=' + this.formvalue.fc_id)
      console.log(res)
      this.getFclist()
      this.deleteDialogVisible = false
    }
  }
}
</script>

<style lang="less" scoped>
</style>
